<?php

use Lib\Utils\UsuariosUtils;
use Lib\Utils\Funciones;
use Lib\Dao\Jocnet\NoticiesDao;
use Illuminate\Support\Facades\Lang;

class JocNetController extends \BaseController { 
	
	var $noticiesDao;
	
	function __construct(){
		$this->noticiesDao = new NoticiesDao();
	}
	
	function index(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.portada');
	}
	
	function nueva_noticia(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.crear_noticia');
	}
	//crearNovaNoticia
	public function crearNovaNoticia(){
		if(Request::ajax()){ 
			$info = Funciones::getPost();
			$aux['idioma'] = "cat";
			$aux['temporada'] = Lang::get('admin.temporada');;
			$aux['nom'] = $info->nom;
			$aux['foto_portada'] = $info->foto_portada;
			$aux['text_desc'] = $info->text_desc;
			$aux['text_noticia'] = $info->text_noticia;
			$aux['data_alta'] = 'CURRENT_TIMESTAMP';
			$aux['actiu_portada'] = $info->actiu_portada;
			$aux['actiu'] = $info->actiu;
			return Response::json($this->noticiesDao->insertNuevaNoticia($aux));
		}
	}
	
	public function formModificarNoticies(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.modificar_noticies');
	}
	
	public function modificarNoticia(){
		
		if(Request::ajax()){
			$info= Funciones::getPost();
			$aux['id'] = $info->id;
			$aux['idioma'] = "cat";
			$aux['temporada'] = Lang::get('admin.temporada');
			$aux['nom'] = $info->nom;
			$aux['foto_portada'] = $info->foto_portada;
			$aux['text_desc'] = $info->text_desc;
			$aux['text_noticia'] = $info->text_noticia;
			$aux['data_alta'] = 'CURRENT_TIMESTAMP';
			$aux['actiu_portada'] = $info->actiu_portada;
			$aux['actiu'] = $info->actiu;
			$result = $this->noticiesDao->updateNoticia($aux);
			return Response::json($result);
		}
		
	}
	
	public function busquedaNoticiesPerNom(){
		return Response::json($this->noticiesDao->getNoticiesPerBusquedaNom($_POST['nom']));
	}
	
	public function getNoticiaPerId(){
		return Response::json($this->noticiesDao->getNoticiaPerId($_POST['id']));
	}
	
	public function updateNoticia(){
		
	}
	
	public function crearSorteig(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.crear_sorteo');
	}
	
	public function buscadorSortejos(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.buscador_sorteos');
	}
	
	public function modificarSortejos(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.modificar_sorteos');
	}
	
	public function escollirGuanyadors(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.escollir_guanyadors');
	}
	
	public function editarGalerias(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.editar_galerias');
	}
	
	public function usuarisRegistrats(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.usuaris_registrats');
	}
	
	public function codisJugats(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.codis_jugats');
	}
	
	public function historialGuanyadors(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.historial_guanyadors');
	}
	
	public function logs(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.logs');
	}
	
	public function graficas(){
		$this->getMenuUsuario();
		$this->layout->content = View::make('jocnet.graficas');
	}
	
	function __destruct(){
		$this->noticiesDao;
	}
	
}

?>